﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Crosland.Automotriz.Logic.ControlExeption;

namespace Crosland.Automotriz.Logic.ControlExeption
{
    public class Logg
    {
        private string sLogFormat;
        private string sErrorTime;
        private static StreamWriter sw;
        public Logg()
        {
            sLogFormat = String.Format("{0} , {1} , ", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString());

            string sYear = DateTime.Now.Year.ToString();
            string sMonth = DateTime.Now.Month.ToString();
            string sDay = DateTime.Now.Day.ToString();
            sErrorTime = sYear + sMonth + sDay;
        }
        public void ErrorLog(string sPathName, string msgUsu, string msgReal, string pagError, string metError, string codUsu,int numberLine)
        {
            try
            {
                sw = new StreamWriter(sPathName, true);
                sw.WriteLine(String.Format("{0}{1} , {2} , {3} , {4} , {5} , {6}", sLogFormat, msgUsu, msgReal, pagError, metError, codUsu, numberLine ));

            }
            catch (ArgumentNullException e)
            {
                throw new DataException("Parameters vacios", e);
            }
            catch (Exception e)
            {
                throw new RunException("No se ha podido guardar datos en el archivo log  ", e);
            }
            finally
            {
                sw.Flush();
                sw.Close();
            }

        }

    }
}
